<template>
    <el-card shadow="never">
        <yun-table
                :columns="columns"
                search="nickname,mobile"
                :common-search="false"
                ref="yuntable"
                toolbar="refresh,add,edit,del,more"
                :auth="{
                    add:{:$auth->check('app\\admin\\controller\\delivery\\Goods','add')},
                    edit:{:$auth->check('app\\admin\\controller\\delivery\\Goods','edit')},
                    del:{:$auth->check('app\\admin\\controller\\delivery\\Goods','del')},
                    multi:{:$auth->check('app\\admin\\controller\\delivery\\Goods','multi')},
                }"
                :extend="extend">
        </yun-table>
    </el-card>
</template>
<script>
    import table from "@components/Table.js";
    export default{
        components:{
            'YunTable':table
        },
        data:{
            extend:{
                index_url: 'delivery/goods/index',
                add_url: 'delivery/goods/add',
                edit_url: 'delivery/goods/edit',
                del_url: 'delivery/goods/del',
                multi_url: 'delivery/goods/multi',
            },
            columns:[
                {checkbox: true},
                {"field":"id","title":"ID",width:80,"operate":false},
                {"field":"name","title":"商品名称","operate":false},
                {"field":"des","title":"商品简介",width:300,"operate":false},
                {
                    "field":"spec",
                    "title":"商品规格",
                    "operate":false,
                    "rules":"required",
                    "formatter": function (data, row) {
                        let html=Yunqi.formatter.html;
                        let value='';
                        data.forEach(function (item) {
                            value+=item.name+'：'+item.price+'元/'+item.unit+'<br>';
                        });
                        html.value=value;
                        return html;
                    }
                },
                {"field":"icon","title":"首页图标","operate":false,width:120,"formatter":Yunqi.formatter.image},
                {"field":"img","title":"介绍图片","operate":false,"formatter":Yunqi.formatter.images},
                {"field":"status","title":"状态","operate":false,"searchList":{"normal":"正常","hidden":"隐藏"},"formatter":Yunqi.formatter.switch},
                {
                    field: 'operate',
                    title: __('操作'),
                    width:130,
                    action:{
                        spec:{
                            text:'规格',
                            icon:'fa fa-list',
                            tooltip:true,
                            method:'setSpec',
                            type:'warning'
                        },
                        edit:true,
                        del:true,
                    },
                }
            ]
        },
        methods: {
            setSpec:function (row){
                let that=this;
                Yunqi.api.open({
                    title:'设置规格',
                    url:'delivery/goods/setSpec?goods_id='+row.id,
                    icon:'fa fa-list',
                    close:function (i){
                        if(i){
                            that.$refs.yuntable.reload();
                        }
                    }
                });
            }
        }
    }
</script>
<style>

</style>